package com.example.jstlweb.configuration;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.view.JstlView;

@Configuration
@EnableWebMvc
public class WebMvcConfg implements WebMvcConfigurer {


    //    @Bean
//    public InternalResourceViewResolver viewResolver(){
//        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
//        viewResolver.setPrefix("/WEB-INF/view/");
//        viewResolver.setSuffix(".html");
//        return viewResolver;
//    }
//
//    /**
//     * SpringBoot设置首页
//     */
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        WebMvcConfigurer.super.addViewControllers(registry);
//        registry.addViewController("/").setViewName("index");
//        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
//    }
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable("jsp");
    }

    /* 拦截器 */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //TODO HandlerInterceptor

    }

    /*资源处理器*/
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resource/**").addResourceLocations("/resource/");
        registry.addResourceHandler("/**/*.css").addResourceLocations("/WEB-INF/view/");
        registry.addResourceHandler("/**/*.js").addResourceLocations("/WEB-INF/view/");
        registry.addResourceHandler("/**/*.png").addResourceLocations("/WEB-INF/view/");
        registry.addResourceHandler("/**/*.jpg").addResourceLocations("/WEB-INF/view/");
        registry.addResourceHandler("/**/*.svg").addResourceLocations("/WEB-INF/view/");
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/view/", ".html");
        registry.enableContentNegotiation(new JstlView());
    }
}
